import time
import hashlib
import requests

cookies = {
    'union': '{"amug_biz":"comad","amug_fl_src":"sem_bing","creative_url":"https%3A%2F%2Fwww.1688.com%2Fzw%2Fhamlet.html%3Fscene%3D6%26cosite%3Dbingjj_pz%26","creative_time":1742433603888}',
    'cookie2': '1da77035f65f1662744a6b77483dd1f4',
    't': '4800595696cc458e1b5b725b63b9b847',
    '_tb_token_': 'e6e1e3b3586be',
    'cna': 'RFtiIOPjBAMCAXrj2dag3mNG',
    'xlly_s': '1',
    'leftMenuLastMode': 'COLLAPSE',
    'leftMenuModeTip': 'shown',
    'keywordsHistory': '%E7%94%B5%E8%84%91',
    'mtop_partitioned_detect': '1',
    '_m_h5_tk': '425f507a3d244fc3326873a9be83a3ef_1742446548790',
    '_m_h5_tk_enc': '71e2aec25c9831d31893c6684459d7e7',
    '_user_vitals_session_data_': '{"user_line_track":true,"ul_session_id":"h865klhwedw","last_page_id":"s.1688.com%2Fnbdxvmgm1x"}',
    'isg': 'BFRUAoGGz9zsF1uQ83ztZXk5JZLGrXiXSEvrg-414F9i2fQjFr1IJwpI29HBJrDv',
    'tfstk': 'gF2mXgbXiSlfZ54pkzkf9GV3YU5-MnMsrPptWA3Na4uWHflqb3-rrPgxMxuvIG47P5FOcfUuSy4LMcBjkdDgjPat_R3TInwu-dpAlsZwIAHNJwBdpotjCA7KC7NQyEiZAmWt_qrrhcBb_6BRpoZX4nYNv7WpSwBH5xRZ7PkramiqQCo2Qgcrvckw3fJ2aUuSbAkZucWyUDo9uVlw3gqrPckZ7PlqMZbquRyYUa7VWCCL8beomj0Uq699CyJKg2rqrd7_omYI8oukQduvWPP4qoQDduHbQymLkTJ0-lrQ_b2Mzw0_Euy4_uTc4vquwWh0ZZJiy-niTAlkbdroQSGanvWer0NzD5ybohvZc-eKs2GlbdGtUJhUTrx1AukqbPGQBw9julrQdWHhnei0akDl4AAyTqDJC0STUCOsg0ioJ8OH3iiUpWtPqgAn5joS02IlqCOsg0ioJgjktlGqVmud.',
}

headers = {
    'accept': '*/*',
    'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
    'referer': 'https://s.1688.com/',
    'sec-ch-ua': '"Chromium";v="134", "Not:A-Brand";v="24", "Microsoft Edge";v="134"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
    'sec-fetch-dest': 'script',
    'sec-fetch-mode': 'no-cors',
    'sec-fetch-site': 'same-site',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0',
    # 'cookie': 'union={"amug_biz":"comad","amug_fl_src":"sem_bing","creative_url":"https%3A%2F%2Fwww.1688.com%2Fzw%2Fhamlet.html%3Fscene%3D6%26cosite%3Dbingjj_pz%26","creative_time":1742433603888}; cookie2=1da77035f65f1662744a6b77483dd1f4; t=4800595696cc458e1b5b725b63b9b847; _tb_token_=e6e1e3b3586be; cna=RFtiIOPjBAMCAXrj2dag3mNG; xlly_s=1; leftMenuLastMode=COLLAPSE; leftMenuModeTip=shown; keywordsHistory=%E7%94%B5%E8%84%91; mtop_partitioned_detect=1; _m_h5_tk=425f507a3d244fc3326873a9be83a3ef_1742446548790; _m_h5_tk_enc=71e2aec25c9831d31893c6684459d7e7; _user_vitals_session_data_={"user_line_track":true,"ul_session_id":"h865klhwedw","last_page_id":"s.1688.com%2Fnbdxvmgm1x"}; isg=BFRUAoGGz9zsF1uQ83ztZXk5JZLGrXiXSEvrg-414F9i2fQjFr1IJwpI29HBJrDv; tfstk=gF2mXgbXiSlfZ54pkzkf9GV3YU5-MnMsrPptWA3Na4uWHflqb3-rrPgxMxuvIG47P5FOcfUuSy4LMcBjkdDgjPat_R3TInwu-dpAlsZwIAHNJwBdpotjCA7KC7NQyEiZAmWt_qrrhcBb_6BRpoZX4nYNv7WpSwBH5xRZ7PkramiqQCo2Qgcrvckw3fJ2aUuSbAkZucWyUDo9uVlw3gqrPckZ7PlqMZbquRyYUa7VWCCL8beomj0Uq699CyJKg2rqrd7_omYI8oukQduvWPP4qoQDduHbQymLkTJ0-lrQ_b2Mzw0_Euy4_uTc4vquwWh0ZZJiy-niTAlkbdroQSGanvWer0NzD5ybohvZc-eKs2GlbdGtUJhUTrx1AukqbPGQBw9julrQdWHhnei0akDl4AAyTqDJC0STUCOsg0ioJ8OH3iiUpWtPqgAn5joS02IlqCOsg0ioJgjktlGqVmud.',
}
timestamp_seconds = time.time()
# 转换为 13 位毫秒级时间戳

time_stamp=str(int(timestamp_seconds * 1000))

params = {
    'jsv': '2.7.2',
    'appKey': '12574478',
    't': time_stamp,
    'sign': 'abcc219bf18164b4f645446f99765e20',
    'api': 'mtop.relationrecommend.WirelessRecommend.recommend',
    'v': '2.0',
    'jsonpIncPrefix': 'reqTppId_32517_getOfferList',
    'type': 'jsonp',
    'dataType': 'jsonp',
    'callback': 'mtopjsonpreqTppId_32517_getOfferList6',
    'data': '{"appId":32517,"params":"{\\"beginPage\\":\\"9\\",\\"pageSize\\":60,\\"method\\":\\"getOfferList\\",\\"pageId\\":\\"CJ7M8GyUzJ8SKJvYKty1V6stob8PJaRbW233FYO7S99Izy2q\\",\\"verticalProductFlag\\":\\"pcmarket\\",\\"searchScene\\":\\"pcOfferSearch\\",\\"charset\\":\\"GBK\\",\\"spm\\":\\"a260k.home2024.searchbox.0\\",\\"keywords\\":\\"%B5%E7%C4%D4\\"}"}',
}

sign='425f507a3d244fc3326873a9be83a3ef'+"&"+str(int(timestamp_seconds * 1000))+"&"+'12574478'+"&"+params['data']

# sign='1596fe19ae3ee1ae37fd8fe478cdf9d1&1742445529967&12574478&{"appId":32517,"params":"{\\"beginPage\\":\\"4\\",\\"pageSize\\":60,\\"method\\":\\"getOfferList\\",\\"pageId\\":\\"MvzV2PApDPprTCghJxiJGuJiNNl4t7FDnN0eP2zO6yiWY5sC\\",\\"verticalProductFlag\\":\\"pcmarket\\",\\"searchScene\\":\\"pcOfferSearch\\",\\"charset\\":\\"GBK\\",\\"spm\\":\\"a260k.home2024.searchbox.0\\",\\"keywords\\":\\"%B5%E7%C4%D4\\"}"}'
print(sign)
md5_hash = hashlib.md5()
md5_hash.update(sign.encode('utf-8'))

# 获取 MD5 哈希值，以十六进制字符串形式输出
md5_hex = md5_hash.hexdigest()
print('================')
print(md5_hex)
params['sign']=md5_hex
print(params)
response = requests.get(
    'https://h5api.m.1688.com/h5/mtop.relationrecommend.wirelessrecommend.recommend/2.0/',
    params=params,
    cookies=cookies,
    headers=headers,
)
print(response.text)